<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>函数 | MXY 1.0版Python整理</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../../home/5.函数及作用域/2.函数文档.html" />
    
    
    <link rel="prev" href="../../home/4.流程控制/2.循环结构.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="5.1"
        data-chapter-title="函数"
        data-filepath="home/5.函数及作用域/1.函数.md"
        data-basepath="../.."
        data-revision="Mon Oct 22 2018 08:32:35 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        MXY整理版Python基础
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" >
            
            <span><b>1.</b> Python的安装和简介</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="home/1.Python的安装和简介/1.python基础知识.html">
            
                
                    <a href="../../home/1.Python的安装和简介/1.python基础知识.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        Python的基础知识
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="home/1.Python的安装和简介/2.python的安装及版本检测.html">
            
                
                    <a href="../../home/1.Python的安装和简介/2.python的安装及版本检测.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        Python安装及版本检测
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="home/1.Python的安装和简介/3.第一个python程序.html">
            
                
                    <a href="../../home/1.Python的安装和简介/3.第一个python程序.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        第一个Python程序
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" >
            
            <span><b>2.</b> Python的基本语法</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="home/2.Python的基本语法/1.注释及语句分类.html">
            
                
                    <a href="../../home/2.Python的基本语法/1.注释及语句分类.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        注释及语句分类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="home/2.Python的基本语法/2.命名方式和关键字.html">
            
                
                    <a href="../../home/2.Python的基本语法/2.命名方式和关键字.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        命名方式和关键字
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" >
            
            <span><b>3.</b> Python的变量及数据类型</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="home/3.变量和数据类型/1.变量.html">
            
                
                    <a href="../../home/3.变量和数据类型/1.变量.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        变量
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="home/3.变量和数据类型/2.数据类型.html">
            
                
                    <a href="../../home/3.变量和数据类型/2.数据类型.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        数据类型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="home/3.变量和数据类型/3.数据类型转换.html">
            
                
                    <a href="../../home/3.变量和数据类型/3.数据类型转换.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        数据类型转换
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="home/3.变量和数据类型/4.运算和运算符.html">
            
                
                    <a href="../../home/3.变量和数据类型/4.运算和运算符.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        数据类型转换
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" >
            
            <span><b>4.</b> Python的流程控制</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="home/4.流程控制/1.顺序结构和分支结构.html">
            
                
                    <a href="../../home/4.流程控制/1.顺序结构和分支结构.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        顺序结构和分支结构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="home/4.流程控制/2.循环结构.html">
            
                
                    <a href="../../home/4.流程控制/2.循环结构.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        循环结构
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" >
            
            <span><b>5.</b> 函数及作用域</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="5.1" data-path="home/5.函数及作用域/1.函数.html">
            
                
                    <a href="../../home/5.函数及作用域/1.函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="home/5.函数及作用域/2.函数文档.html">
            
                
                    <a href="../../home/5.函数及作用域/2.函数文档.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        函数文档
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="home/5.函数及作用域/3.变量的作用域.html">
            
                
                    <a href="../../home/5.函数及作用域/3.变量的作用域.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        变量的作用域
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="home/5.函数及作用域/4.内部函数和闭包操作.html">
            
                
                    <a href="../../home/5.函数及作用域/4.内部函数和闭包操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        内部函数和闭包操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="home/5.函数及作用域/5.lambda表达式.html">
            
                
                    <a href="../../home/5.函数及作用域/5.lambda表达式.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        lambda表达式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="home/5.函数及作用域/6.高阶函数.html">
            
                
                    <a href="../../home/5.函数及作用域/6.高阶函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        高阶函数
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" >
            
            <span><b>6.</b> 内置函数及操作</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="home/6.内置函数及操作/1.字符串相关.html">
            
                
                    <a href="../../home/6.内置函数及操作/1.字符串相关.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        字符串相关
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="home/6.内置函数及操作/2.format格式字符串.html">
            
                
                    <a href="../../home/6.内置函数及操作/2.format格式字符串.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        format格式字符串
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="home/6.内置函数及操作/3.内建函数.html">
            
                
                    <a href="../../home/6.内置函数及操作/3.内建函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        内建函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="home/6.内置函数及操作/4.列表.html">
            
                
                    <a href="../../home/6.内置函数及操作/4.列表.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        列表
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="home/6.内置函数及操作/5.元组.html">
            
                
                    <a href="../../home/6.内置函数及操作/5.元组.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        元组
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="home/6.内置函数及操作/6.字典.html">
            
                
                    <a href="../../home/6.内置函数及操作/6.字典.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                        字典
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.7" data-path="home/6.内置函数及操作/7.集合.html">
            
                
                    <a href="../../home/6.内置函数及操作/7.集合.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.7.</b>
                        
                        集合
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.8" data-path="home/6.内置函数及操作/8.文件操作.html">
            
                
                    <a href="../../home/6.内置函数及操作/8.文件操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.8.</b>
                        
                        文件操作
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" >
            
            <span><b>7.</b> 常用的模块</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="home/7.常用模块/1.String模块.html">
            
                
                    <a href="../../home/7.常用模块/1.String模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        String模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="home/7.常用模块/2.math模块.html">
            
                
                    <a href="../../home/7.常用模块/2.math模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        math模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="home/7.常用模块/3.OS模块.html">
            
                
                    <a href="../../home/7.常用模块/3.OS模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.3.</b>
                        
                        OS模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="home/7.常用模块/4.zipfile模块.html">
            
                
                    <a href="../../home/7.常用模块/4.zipfile模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.4.</b>
                        
                        zipfile模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="home/7.常用模块/5.tarfile模块.html">
            
                
                    <a href="../../home/7.常用模块/5.tarfile模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.5.</b>
                        
                        tarfile模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.6" data-path="home/7.常用模块/6.shutil模块.html">
            
                
                    <a href="../../home/7.常用模块/6.shutil模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.6.</b>
                        
                        shutil模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.7" data-path="home/7.常用模块/7.时间相关模块.html">
            
                
                    <a href="../../home/7.常用模块/7.时间相关模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.7.</b>
                        
                        时间相关模块
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8" >
            
            <span><b>8.</b> 面向对象</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1" data-path="home/8.面向对象/1.类和对象-上.html">
            
                
                    <a href="../../home/8.面向对象/1.类和对象-上.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.1.</b>
                        
                        类和对象-上
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="home/8.面向对象/2.类和对象-下.html">
            
                
                    <a href="../../home/8.面向对象/2.类和对象-下.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.2.</b>
                        
                        类和对象-下
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="home/8.面向对象/3.魔术方法.html">
            
                
                    <a href="../../home/8.面向对象/3.魔术方法.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.3.</b>
                        
                        魔术方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.4" data-path="home/8.面向对象/4.装饰器.html">
            
                
                    <a href="../../home/8.面向对象/4.装饰器.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.4.</b>
                        
                        装饰器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.5" data-path="home/8.面向对象/5.抽象类.html">
            
                
                    <a href="../../home/8.面向对象/5.抽象类.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.5.</b>
                        
                        抽象类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.6" data-path="home/8.面向对象/6.错误和异常处理.html">
            
                
                    <a href="../../home/8.面向对象/6.错误和异常处理.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.6.</b>
                        
                        错误和异常处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.7" data-path="home/8.面向对象/7.模块和包.html">
            
                
                    <a href="../../home/8.面向对象/7.模块和包.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.7.</b>
                        
                        模块和包
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="9" >
            
            <span><b>9.</b> tkinter模块</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="9.1" data-path="home/9.tkinter模块/tkinter模块.html">
            
                
                    <a href="../../home/9.tkinter模块/tkinter模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.1.</b>
                        
                        tkinter模块
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="10" data-path="home/10.网络编程/1.网络编程.html">
            
                
                    <a href="../../home/10.网络编程/1.网络编程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        网络编程
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="10.1" data-path="home/10.网络编程/2.TCP编程.html">
            
                
                    <a href="../../home/10.网络编程/2.TCP编程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.1.</b>
                        
                        TCP编程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.2" data-path="home/10.网络编程/3.UDP编程.html">
            
                
                    <a href="../../home/10.网络编程/3.UDP编程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.2.</b>
                        
                        UDP编程
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="11" data-path="home/11.多任务/多任务原理.html">
            
                
                    <a href="../../home/11.多任务/多任务原理.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.</b>
                        
                        多任务
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="11.1" data-path="home/11.多任务/1.多进程实现多任务.html">
            
                
                    <a href="../../home/11.多任务/1.多进程实现多任务.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.1.</b>
                        
                        多进程实现多任务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.2" data-path="home/11.多任务/2.多线程实现多任务.html">
            
                
                    <a href="../../home/11.多任务/2.多线程实现多任务.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.2.</b>
                        
                        多线程实现多任务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.3" data-path="home/11.多任务/3.协程实现多任务.html">
            
                
                    <a href="../../home/11.多任务/3.协程实现多任务.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.3.</b>
                        
                        协程实现多任务
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="12" >
            
            <span><b>12.</b> Python实战项目</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="12.1" data-path="home/12.Python实战项目/1.简易计算器.html">
            
                
                    <a href="../../home/12.Python实战项目/1.简易计算器.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.1.</b>
                        
                        简易计算器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.2" data-path="home/12.Python实战项目/2.自动售货机.html">
            
                
                    <a href="../../home/12.Python实战项目/2.自动售货机.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.2.</b>
                        
                        自动售货机
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.3" data-path="home/12.Python实战项目/3.银行项目.html">
            
                
                    <a href="../../home/12.Python实战项目/3.银行项目.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.3.</b>
                        
                        银行项目
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.4" data-path="home/12.Python实战项目/4.简单的登录注册.html">
            
                
                    <a href="../../home/12.Python实战项目/4.简单的登录注册.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.4.</b>
                        
                        简单的登录注册
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.5" data-path="home/12.Python实战项目/5.双色球.html">
            
                
                    <a href="../../home/12.Python实战项目/5.双色球.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.5.</b>
                        
                        双色球
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.6" data-path="home/12.Python实战项目/6.python垃圾回收机制.html">
            
                
                    <a href="../../home/12.Python实战项目/6.python垃圾回收机制.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.6.</b>
                        
                        python垃圾回收机制
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.7" data-path="home/12.Python实战项目/7.turtle画国旗.html">
            
                
                    <a href="../../home/12.Python实战项目/7.turtle画国旗.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.7.</b>
                        
                        turtle画国旗
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.8" data-path="home/12.Python实战项目/8.turtle画小猪佩奇.html">
            
                
                    <a href="../../home/12.Python实战项目/8.turtle画小猪佩奇.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.8.</b>
                        
                        turtle画小猪佩奇
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.9" data-path="home/12.Python实战项目/9.turtle画个表.html">
            
                
                    <a href="../../home/12.Python实战项目/9.turtle画个表.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.9.</b>
                        
                        turtle画个表
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../" >MXY 1.0版Python整理</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x51FD;&#x6570;-function">&#x51FD;&#x6570; Function</h1>
<hr>
<ul>
<li><p><strong>&#x5B9A;&#x4E49;</strong></p>
<ul>
<li><strong>&#x628A;&#x5177;&#x6709;&#x7279;&#x5B9A;&#x529F;&#x80FD;&#x7684;&#x4EE3;&#x7801;&#x6253;&#x5305;</strong>&#x5C31;&#x662F;&#x51FD;&#x6570;&#x3002;</li>
</ul>
</li>
<li><p><strong>&#x4F5C;&#x7528;</strong></p>
<ol>
<li>&#x63D0;&#x9AD8;&#x4EE3;&#x7801;&#x7684;&#x590D;&#x7528;&#x7387;</li>
<li>&#x63D0;&#x9AD8;&#x5F00;&#x53D1;&#x6548;&#x7387;</li>
<li>&#x4FBF;&#x4E8E;&#x7A0B;&#x5E8F;&#x7684;&#x7EF4;&#x62A4;</li>
</ol>
</li>
<li><p><strong>&#x51FD;&#x6570;&#x7684;&#x547D;&#x540D;&#x89C4;&#x5219;</strong></p>
<ol>
<li>&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x4E2D;&#x6587;&#xFF0C;&#x4F46;&#x662F;python&#x5927;&#x795E;&#x90FD;&#x4E0D;&#x7528;</li>
<li>&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x6570;&#x5B57;&#xFF0C;&#x4F46;&#x662F;&#x6570;&#x5B57;&#x4E0D;&#x80FD;&#x5728;&#x5F00;&#x5934;</li>
<li>&#x51FD;&#x6570;&#x540D;&#x79F0;&#x53EA;&#x80FD;&#x4F7F;&#x7528;&#x6570;&#x5B57;&#x3001;&#x5B57;&#x6BCD;&#x548C;&#x4E0B;&#x5212;&#x7EBF;</li>
<li>&#x5F00;&#x5934;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x4E0B;&#x5212;&#x7EBF;&#xFF0C;&#x4F46;&#x5176;&#x6709;&#x7279;&#x6B8A;&#x542B;&#x4E49;&#xFF0C;&#x4E00;&#x4E2A;&#x4E0B;&#x5212;&#x7EBF;&#x5F00;&#x5934;&#x8868;&#x793A;&#x8BE5;&#x51FD;&#x6570;&#x5F88;&#x91CD;&#x8981;&#xFF0C;&#x8BF7;&#x52FF;&#x968F;&#x610F;&#x4FEE;&#x6539;&#xFF0C;&#x4E24;&#x4E2A;&#x4E0B;&#x5212;&#x7EBF;&#x5F00;&#x5934;&#x8868;&#x793A;&#x79C1;&#x6709;&#x51FD;&#x6570;</li>
<li>&#x4E25;&#x683C;&#x533A;&#x5206;&#x5927;&#x5C0F;&#x5199;</li>
<li>&#x51FD;&#x6570;&#x540D;&#x79F0;&#x8981;&#x5177;&#x6709;&#x63CF;&#x8FF0;&#x6027;</li>
<li>&#x4E0D;&#x80FD;&#x4F7F;&#x7528;&#x5173;&#x952E;&#x5B57;&#x5F53;&#x505A;&#x53D8;&#x91CF;&#x540D;</li>
</ol>
</li>
<li><p><strong>&#x51FD;&#x6570;&#x58F0;&#x660E;&#x65B9;&#x5F0F;</strong></p>
<ol>
<li><p><strong>&#x57FA;&#x672C;&#x683C;&#x5F0F;</strong></p>
<pre><code class="lang-py"> <span class="hljs-function"><span class="hljs-keyword">def</span> &#x51FD;&#x6570;&#x540D;<span class="hljs-params">()</span>:</span>
     <span class="hljs-keyword">pass</span>
</code></pre>
<p> &#x793A;&#x4F8B;</p>
<pre><code class="lang-py"> <span class="hljs-comment">#&#x5B9A;&#x4E49;&#x51FD;&#x6570;</span>
 <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">funName</span><span class="hljs-params">()</span>:</span>
     <span class="hljs-keyword">pass</span> <span class="hljs-comment">#&#x6B64;&#x5904;&#x7F16;&#x5199;&#x529F;&#x80FD;&#x4EE3;&#x7801;</span>

 funName() <span class="hljs-comment">#&#x8C03;&#x7528;</span>

 <span class="hljs-string">&apos;&apos;&apos;&#x6CE8;&#x91CA;&#xFF1A;
 &#x51FD;&#x6570;&#x7684;&#x7279;&#x5F81;&#xFF1A;&#x51FD;&#x6570;&#x5B9A;&#x4E49;&#x4E4B;&#x540E;&#xFF0C;&#x4E0D;&#x4F1A;&#x81EA;&#x52A8;&#x6267;&#x884C;&#xFF0C;&#x53EA;&#x4F1A;&#x5728;&#x8C03;&#x7528;&#x7684;&#x65F6;&#x5019;&#x6267;&#x884C;&#x3002;&#x4E0D;&#x8C03;&#x7528;&#xFF0C;&#x4E0D;&#x6267;&#x884C;&#x3002;
 &apos;&apos;&apos;</span>
</code></pre>
</li>
<li><p><strong>&#x5E26;&#x6709;&#x53C2;&#x6570;&#x7684;&#x683C;&#x5F0F;</strong></p>
<pre><code class="lang-py"> <span class="hljs-function"><span class="hljs-keyword">def</span> &#x51FD;&#x6570;&#x540D;<span class="hljs-params">(&#x53C2;&#x6570;<span class="hljs-number">1</span>&#xFF0C;&#x53C2;&#x6570;<span class="hljs-number">2.</span>..)</span>:</span>
     <span class="hljs-keyword">pass</span>
</code></pre>
<p> &#x793A;&#x4F8B;</p>
<pre><code class="lang-py"> <span class="hljs-comment">#&#x5B9A;&#x4E49;&#x5E26;&#x6709;&#x53C2;&#x6570;&#x7684;&#x51FD;&#x6570;</span>
 <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">funName</span><span class="hljs-params">(arg)</span>:</span>
     print(<span class="hljs-string">&apos;&#x63A5;&#x6536;&#x5230;&#x7684;&#x53C2;&#x6570;&#xFF1A;&apos;</span>,arg)

 funName(<span class="hljs-number">666</span>) <span class="hljs-comment">#&#x8C03;&#x7528;</span>

 <span class="hljs-string">&apos;&apos;&apos;&#x6CE8;&#x91CA;&#xFF1A;
 &#x5F62;&#x53C2;&#xFF1A;&#x5F62;&#x5F0F;&#x4E0A;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x58F0;&#x660E;&#x51FD;&#x6570;&#x65F6;&#xFF0C;&#x62EC;&#x53F7;()&#x4E2D;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x662F;&#x5F62;&#x53C2;&#x3002;
 &#x5B9E;&#x53C2;&#xFF1A;&#x5B9E;&#x9645;&#x4E0A;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x8C03;&#x7528;&#x51FD;&#x6570;&#x662F;&#xFF0C;&#x62EC;&#x53F7;()&#x4E2D;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x662F;&#x5B9E;&#x53C2;&#x3002;
 &#x5B9E;&#x53C2;&#x5C06;&#x503C;&#x4F20;&#x9012;&#x7ED9;&#x5F62;&#x53C2;&#x7684;&#x672C;&#x8D28;&#x8FC7;&#x7A0B;&#xFF0C;&#x672C;&#x8D28;&#x4E0A;&#x5C31;&#x662F;&#x7B80;&#x5355;&#x7684;&#x53D8;&#x91CF;&#x8D4B;&#x503C;&#x3002;
 &apos;&apos;&apos;</span>
</code></pre>
</li>
<li><p><strong>&#x5E26;&#x6709;&#x9ED8;&#x8BA4;&#x503C;&#x7684;&#x53C2;&#x6570;&#x7684;&#x683C;&#x5F0F;</strong></p>
<pre><code class="lang-py"> <span class="hljs-function"><span class="hljs-keyword">def</span> &#x51FD;&#x6570;&#x540D;<span class="hljs-params">(&#x53C2;&#x6570;<span class="hljs-number">1</span> = &#x503C;<span class="hljs-number">1</span>,&#x53C2;&#x6570;<span class="hljs-number">2</span> = &#x503C;<span class="hljs-number">2.</span>..)</span>:</span>
     <span class="hljs-keyword">pass</span>
</code></pre>
<p> &#x793A;&#x4F8B;</p>
</li>
</ol>
</li>
</ul>
<pre><code>    ```py
    #&#x5B9A;&#x4E49;&#x5E26;&#x6709;&#x9ED8;&#x8BA4;&#x503C;&#x53C2;&#x6570;&#x7684;&#x51FD;&#x6570;
    def funName(arg = &apos;jack&apos;):
        print(&apos;&#x53C2;&#x6570;&#x503C;&#xFF1A;&apos;,arg)

    funName() #&#x8C03;&#x7528;&#x65B9;&#x5F0F;&#x4E00;
    funName(&apos;mark&apos;) #&#x8C03;&#x7528;&#x65B9;&#x5F0F;&#x4E8C;  &#x8C03;&#x7528;&#x65F6;&#x4F20;&#x7684;&#x53C2;&#x6570;&#x4F1A;&#x8986;&#x76D6;&#x9ED8;&#x8BA4;&#x503C;

    &apos;&apos;&apos;&#x6CE8;&#x91CA;&#xFF1A;
    &#x5982;&#x679C;&#x5F62;&#x53C2;&#x6709;&#x9ED8;&#x8BA4;&#x503C;&#xFF0C;&#x8C03;&#x7528;&#x65F6;&#x53EF;&#x4EE5;&#x4E0D;&#x9700;&#x8981;&#x4F20;&#x53C2;&#xFF0C;&#x7CFB;&#x7EDF;&#x4F1A;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x53C2;&#x6570;&#x7684;&#x9ED8;&#x8BA4;&#x503C;&#x3002;
    &#x8C03;&#x7528;&#x65F6;&#x7ED9;&#x6709;&#x9ED8;&#x8BA4;&#x503C;&#x7684;&#x53C2;&#x6570;&#x4F20;&#x53C2;&#xFF0C;&#x5B9E;&#x53C2;&#x4F1A;&#x8986;&#x76D6;&#x5F62;&#x53C2;&#x7684;&#x9ED8;&#x8BA4;&#x503C;&#x3002;&#x672C;&#x8D28;&#x4E0A;&#x5C31;&#x662F;&#x53D8;&#x91CF;&#x7684;&#x91CD;&#x65B0;&#x8D4B;&#x503C;&#x3002;
    &apos;&apos;&apos;
    ```

1. **&#x4F7F;&#x7528;&#x5173;&#x952E;&#x5B57;&#x53C2;&#x6570;&#x683C;&#x5F0F;**

    ```py
    def &#x51FD;&#x6570;&#x540D;(&#x5F62;&#x53C2;1 = &#x5B9E;&#x53C2;1,&#x5F62;&#x53C2;2 = &#x5B9E;&#x53C2;2...):
        pass
    ```
    &#x793A;&#x4F8B;


    ```py
    #&#x5B9A;&#x4E49;&#x5E26;&#x6709;&#x9ED8;&#x8BA4;&#x503C;&#x53C2;&#x6570;&#x7684;&#x51FD;&#x6570;
    def funName(name = &apos;jack&apos;,age = 18,sex = &apos;man&apos;):
    print(&apos;name:&apos;,name)
    print(&apos;age:&apos;,age)
    print(&apos;sex:&apos;,sex)

    funName(8,&apos;&#x4E8C;&#x72D7;&apos;,&apos;Superman&apos;) #&#x53C2;&#x6570;&#x8F83;&#x591A;&#x65F6;&#x8D4B;&#x503C;&#x987A;&#x5E8F;&#x98A0;&#x5012;&#xFF0C;&#x5C06;&#x4F1A;&#x5F71;&#x54CD;&#x7A0B;&#x5E8F;&#x6267;&#x884C;&#x7ED3;&#x679C;
    funName(age = 8,name = &apos;&#x4E8C;&#x72D7;&apos;,sex = &apos;Superman&apos;) #&#x5173;&#x952E;&#x5B57;&#x53C2;&#x6570;&#x8D4B;&#x503C;&#x5B8C;&#x7F8E;&#x89E3;&#x51B3;&#x4E0A;&#x9762;&#x7684;&#x95EE;&#x9898;

    &apos;&apos;&apos;&#x6CE8;&#x91CA;&#xFF1A;
    &#x5173;&#x952E;&#x5B57;&#x53C2;&#x6570;&#x5C31;&#x662F;&#x8C03;&#x7528;&#x51FD;&#x6570;&#x65F6;&#xFF0C;&#x5728;&#x5B9E;&#x53C2;&#x524D;&#x9762;&#x6307;&#x5B9A;&#x5F62;&#x53C2;&#x7684;&#x505A;&#x6CD5;&#xFF0C;&#x4E3A;&#x4E86;&#x9632;&#x6B62;&#x53C2;&#x6570;&#x6309;&#x7167;&#x4F4D;&#x7F6E;&#x4F20;&#x9012;&#x51FA;&#x73B0;&#x7684;&#x9519;&#x8BEF;&#x3002;
    &apos;&apos;&apos;
    ``` 

1. **&#x6536;&#x96C6;&#x53C2;&#x6570;&#x4F7F;&#x7528;&#x65B9;&#x6CD5;**

    &#x6536;&#x96C6;&#x53C2;&#x6570;&#x53EF;&#x4EE5;&#x6536;&#x96C6;&#x7684;&#x53C2;&#x6570;&#x4E0D;&#x53D7;&#x6570;&#x91CF;&#x9650;&#x5236;

    * **&#x975E;&#x5173;&#x952E;&#x5B57;&#x6536;&#x96C6;&#x53C2;&#x6570;**

        ```py
        def &#x51FD;&#x6570;&#x540D;(*&#x53C2;&#x6570;&#x540D;):
            pass
        ```
        &#x793A;&#x4F8B;


        ```py
        #&#x5B9A;&#x4E49;&#x5E26;&#x6709;&#x975E;&#x5173;&#x952E;&#x5B57;&#x6536;&#x96C6;&#x53C2;&#x6570;&#x7684;&#x51FD;&#x6570;
        def funName(*arg):
            for v in arg: #&#x904D;&#x5386;
                print(v)

        funName(1,2,3,&apos;a&apos;,&apos;b&apos;,&apos;c&apos;) #&#x8C03;&#x7528;

        &apos;&apos;&apos;&#x6CE8;&#x91CA;&#xFF1A;
        1.&#x975E;&#x5173;&#x952E;&#x5B57;&#x6536;&#x96C6;&#x53C2;&#x6570;&#xFF0C;&#x5728;&#x5F62;&#x53C2;&#x524D;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;*&#x5373;&#x53EF;
        2.&#x975E;&#x5173;&#x952E;&#x5B57;&#x6536;&#x96C6;&#x53C2;&#x6570;&#xFF0C;&#x6536;&#x96C6;&#x7684;&#x5B9E;&#x53C2;&#x4F1A;&#x7EC4;&#x6210;&#x4E00;&#x4E2A;&#x5143;&#x7EC4;
        3.&#x975E;&#x5173;&#x952E;&#x5B57;&#x6536;&#x96C6;&#x53C2;&#x6570;&#xFF0C;&#x63A5;&#x53D7;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x5F62;&#x53C2;&#x63A5;&#x53D7;&#x7684;&#x975E;&#x5173;&#x952E;&#x5B57;&#x5B9E;&#x53C2;
        4.&#x975E;&#x5173;&#x952E;&#x5B57;&#x6536;&#x96C6;&#x53C2;&#x6570;&#xFF0C;&#x53EF;&#x4EE5;&#x548C;&#x666E;&#x901A;&#x7684;&#x5F62;&#x53C2;&#x5171;&#x5B58;
        &apos;&apos;&apos;
        ``` 

    * **&#x5173;&#x952E;&#x5B57;&#x6536;&#x96C6;&#x53C2;&#x6570;**

        ```py
        def &#x51FD;&#x6570;&#x540D;(**&#x53C2;&#x6570;&#x540D;):
            pass
        ```
        &#x793A;&#x4F8B;

        ```py
        #&#x5B9A;&#x4E49;&#x5E26;&#x6709;&#x5173;&#x952E;&#x5B57;&#x6536;&#x96C6;&#x53C2;&#x6570;&#x7684;&#x51FD;&#x6570;
        def funName(**car):
            for v in car: #&#x904D;&#x5386;
                print(v,&apos;value : &apos;,car[v])

        funName(a = &apos;&#x5361;&#x8F66;&apos;,b = &apos;&#x706B;&#x8F66;&apos;,c = &apos;&#x516C;&#x4EA4;&#x8F66;&apos;) #&#x8C03;&#x7528;

        &apos;&apos;&apos;&#x6CE8;&#x91CA;&#xFF1A;
        1.&#x5173;&#x952E;&#x5B57;&#x6536;&#x96C6;&#x53C2;&#x6570;&#xFF0C;&#x5728;&#x5F62;&#x53C2;&#x524D;&#x6DFB;&#x52A0;&#x4E24;&#x4E2A;*
        2.&#x5173;&#x952E;&#x5B57;&#x6536;&#x96C6;&#x53C2;&#x6570;&#xFF0C;&#x6536;&#x96C6;&#x7684;&#x5B9E;&#x53C2;&#x4F1A;&#x7EC4;&#x6210;&#x4E00;&#x4E2A;&#x5B57;&#x5178;&#xFF0C;&#x5F62;&#x53C2;&#x540D;&#x4F5C;&#x4E3A;&#x952E;&#xFF0C;&#x503C;&#x4F5C;&#x4E3A;&#x503C;
        3.&#x5173;&#x952E;&#x5B57;&#x6536;&#x96C6;&#x53C2;&#x6570;&#xFF0C;&#x4EC5;&#x63A5;&#x6536;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x5F62;&#x53C2;&#x63A5;&#x6536;&#x7684;&#x5173;&#x952E;&#x5B57;&#x53C2;&#x6570;
        4.&#x5173;&#x952E;&#x5B57;&#x6536;&#x96C6;&#x53C2;&#x6570;&#xFF0C;&#x53EF;&#x4EE5;&#x548C;&#x666E;&#x901A;&#x7684;&#x5F62;&#x53C2;&#x5171;&#x5B58;
        &apos;&apos;&apos;
        ``` 

    * **&#x591A;&#x79CD;&#x53C2;&#x6570;&#x6DF7;&#x5408;&#x4F7F;&#x7528;&#x5E94;&#x5F53;&#x6CE8;&#x610F;**
        * &#x5B9A;&#x4E49;&#x51FD;&#x6570;&#x65F6;&#x5C3D;&#x91CF;&#x907F;&#x514D;&#x591A;&#x79CD;&#x53C2;&#x6570;&#x683C;&#x5F0F;&#x6DF7;&#x5408;(&#x666E;&#x901A;&#x53C2;&#x6570;&#xFF0C;&#x5173;&#x952E;&#x5B57;&#x53C2;&#x6570;&#xFF0C;&#x4E24;&#x79CD;&#x6536;&#x96C6;&#x53C2;&#x6570;) 
        * &#x666E;&#x901A;&#x53C2;&#x6570;&#x548C;&#x5173;&#x952E;&#x5B57;&#x53C2;&#x6570;&#x5FC5;&#x987B;&#x5728;&#x4E24;&#x79CD;&#x6536;&#x96C6;&#x53C2;&#x6570;&#x4E4B;&#x524D;
        * &#x975E;&#x5173;&#x952E;&#x5B57;&#x6536;&#x96C6;&#x53C2;&#x6570;&#xFF0C;&#x5FC5;&#x987B;&#x5728;&#x5173;&#x952E;&#x5B57;&#x6536;&#x96C6;&#x53C2;&#x6570;&#x4E4B;&#x524D;
        * &#x5982;&#x679C;&#x591A;&#x79CD;&#x53C2;&#x6570;&#x6DF7;&#x5408;&#x5728;&#x4E00;&#x8D77;&#x7528;&#xFF0C;&#x5FC5;&#x987B;&#x6CE8;&#x610F;&#x7981;&#x6B62;&#x53C2;&#x6570;&#x591A;&#x6B21;&#x8D4B;&#x503C;&#x64CD;&#x4F5C;(&#x666E;&#x901A;&#x53C2;&#x6570;&#x8D4B;&#x503C;&#x5728;&#x524D;&#xFF0C;&#x5173;&#x952E;&#x5B57;&#x53C2;&#x6570;&#x8D4B;&#x503C;&#x5728;&#x540E;
</code></pre><hr>
<h2 id="&#x51FD;&#x6570;&#x7684;&#x8FD4;&#x56DE;&#x503C;">&#x51FD;&#x6570;&#x7684;&#x8FD4;&#x56DE;&#x503C;</h2>
<ul>
<li><p>&#x6839;&#x636E;&#x6267;&#x884C;&#x51FD;&#x6570;&#x5B8C;&#x6BD5;&#x662F;&#x5426;&#x53EF;&#x4EE5;&#x5F97;&#x5230;&#x4E00;&#x4E2A;&#x7ED3;&#x679C;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5C06;&#x51FD;&#x6570;&#x5206;&#x4E3A;&#x4E24;&#x79CD;&#x7C7B;&#x578B;&#x3002;</p>
<ul>
<li><p><strong>&#x6267;&#x884C;&#x8FC7;&#x7A0B;&#x51FD;&#x6570;</strong></p>
<ul>
<li>&#x51FD;&#x6570;&#x6267;&#x884C;&#x5B8C;&#x6BD5;&#x4E4B;&#x540E;&#xFF0C;&#x63A5;&#x6536;&#x4E0D;&#x5230;&#x4EFB;&#x4F55;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#x7684;&#x51FD;&#x6570;&#x3002;&#x5982;&#xFF1A;print()</li>
</ul>
</li>
<li><p><strong>&#x5177;&#x6709;&#x8FD4;&#x56DE;&#x503C;&#x5F97;&#x51FD;&#x6570;</strong></p>
<ul>
<li>&#x51FD;&#x6570;&#x6267;&#x884C;&#x5B8C;&#x6BD5;&#x4E4B;&#x540E;&#xFF0C;&#x4F1A;&#x4EA7;&#x751F;&#x4E00;&#x4E2A;&#x7ED3;&#x679C;&#xFF0C;&#x53EF;&#x4EE5;&#x88AB;&#x63A5;&#x6536;&#x548C;&#x4F7F;&#x7528;&#x7684;&#x51FD;&#x6570;&#x3002;&#x5982;&#xFF1A;type()</li>
</ul>
<p>&#x683C;&#x5F0F;</p>
<pre><code class="lang-py"><span class="hljs-function"><span class="hljs-keyword">def</span> &#x51FD;&#x6570;&#x540D;<span class="hljs-params">(&#x53C2;&#x6570;...)</span>:</span>
  Python code...
  <span class="hljs-keyword">return</span> &#x8FD4;&#x56DE;&#x503C; <span class="hljs-comment">#&#x6709;return&#x7684;&#x51FD;&#x6570;&#xFF0C;&#x5C31;&#x662F;&#x6709;&#x8FD4;&#x56DE;&#x503C;&#x7684;&#x51FD;&#x6570;</span>

&#x53D8;&#x91CF;&#x540D; = &#x51FD;&#x6570;&#x540D;(&#x53C2;&#x6570;...)  <span class="hljs-comment">#&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x53BB;&#x63A5;&#x6536;&#x51FD;&#x6570;&#x7684;&#x8FD4;&#x56DE;&#x503C;</span>

<span class="hljs-string">&apos;&apos;&apos;&#x6CE8;&#x91CA;&#xFF1A;
1.&#x5177;&#x6709;return&#x8BED;&#x53E5;&#x7684;&#x51FD;&#x6570;&#xFF0C;&#x6211;&#x4EEC;&#x79F0;&#x4E4B;&#x4E3A;&#x5177;&#x6709;&#x8FD4;&#x56DE;&#x503C;&#x7684;&#x51FD;&#x6570;
2.return&#x53EF;&#x4EE5;&#x4E3A;&#x5F53;&#x524D;&#x51FD;&#x6570;&#x6267;&#x884C;&#x5B8C;&#x6BD5;&#x7684;&#x51FD;&#x6570;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x7ED3;&#x679C;&#xFF0C;&#x8FD9;&#x4E2A;&#x8FD4;&#x56DE;&#x503C;&#x53EF;&#x4EE5;&#x7528;&#x53D8;&#x91CF;&#x63A5;&#x6536;
3.return&#x6267;&#x884C;&#x4E4B;&#x540E;&#xFF0C;&#x51FD;&#x6570;&#x5C06;&#x4F1A;&#x7EC8;&#x6B62;&#xFF0C;&#x6240;&#x4EE5;return&#x4E4B;&#x540E;&#x7684;&#x8BED;&#x53E5;&#x662F;&#x4E0D;&#x4F1A;&#x88AB;&#x6267;&#x884C;&#x7684;
4.&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x591A;&#x4E2A;return&#x8BED;&#x53E5;&#xFF0C;&#x4F46;&#x662F;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x4F1A;&#x88AB;&#x6267;&#x884C;&#xFF0C;&#x4E00;&#x822C;&#x90FD;&#x662F;&#x653E;&#x5165;&#x5206;&#x652F;&#x7ED3;&#x6784;&#x4E2D;
5.&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x5982;&#x679C;&#x9700;&#x8981;&#x8FD4;&#x56DE;&#x591A;&#x4E2A;&#x6570;&#x636E;&#xFF0C;&#x4F7F;&#x7528;&#x590D;&#x5408;&#x6570;&#x636E;&#x7C7B;&#x578B;(list,tuple,set,dict)&#x6765;&#x64CD;&#x4F5C;&#x5373;&#x53EF;
&apos;&apos;&apos;</span>
</code></pre>
</li>
<li><p><strong>return&#x7684;&#x4F5C;&#x7528;</strong></p>
<ul>
<li>&#x4E3A;&#x51FD;&#x6570;&#x7684;&#x8FD0;&#x884C;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x7ED3;&#x679C;</li>
<li>&#x7EC8;&#x6B62;&#x51FD;&#x6570;&#x6267;&#x884C;,&#x4E00;&#x65E6;&#x51FD;&#x6570;&#x8FD0;&#x884C;&#x5230;&#x4E86;return,&#x5219;&#x5728;return&#x4E4B;&#x540E;&#x7684;&#x4EE3;&#x7801;&#x5C06;&#x4E0D;&#x4F1A;&#x8FD0;&#x884C;</li>
</ul>
</li>
</ul>
</li>
</ul>
<hr>
<h2 id="&#x9012;&#x5F52;&#x51FD;&#x6570;">&#x9012;&#x5F52;&#x51FD;&#x6570;</h2>
<p><strong>&#x5728;&#x51FD;&#x6570;&#x5185;&#x8C03;&#x7528;&#x5F53;&#x524D;&#x51FD;&#x6570;&#x672C;&#x8EAB;&#x7684;&#x51FD;&#x6570;&#x5C31;&#x662F;&#x9012;&#x5F52;&#x51FD;&#x6570;</strong></p>
<p><strong>&#x4E00;&#x4E2A;&#x9012;&#x5F52;&#x51FD;&#x6570;</strong></p>
<pre><code class="lang-py"><span class="hljs-comment">#&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x9012;&#x5F52;&#x51FD;&#x6570;</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">func</span><span class="hljs-params">(num)</span>:</span>
    <span class="hljs-comment">#1.&#x8F93;&#x51FA;num</span>
    print(num)
    <span class="hljs-comment">#2.&#x5224;&#x65AD;&#x6761;&#x4EF6;&#xFF0C;&#x4E0D;&#x6539;&#x53D8;num</span>
    <span class="hljs-keyword">if</span> num &lt; <span class="hljs-number">4</span>:
        func(num+<span class="hljs-number">1</span>)
    <span class="hljs-keyword">else</span>:
        print(<span class="hljs-string">&apos;================&apos;</span>)
    <span class="hljs-comment">#3.&#x8F93;&#x51FA;num</span>
    print(num)
<span class="hljs-comment">#&#x8C03;&#x7528;&#x9012;&#x5F52;&#x51FD;&#x6570;</span>
func(<span class="hljs-number">1</span>)
</code></pre>
<p><strong>&#x6267;&#x884C;&#x7ED3;&#x679C;</strong></p>
<p><img src="../images/&#x4E00;&#x4E2A;&#x9012;&#x5F52;&#x51FD;&#x6570;.png" alt=""></p>
<p><strong>&#x5206;&#x6790;</strong></p>
<p>&#x5148;&#x6267;&#x884C;fucn(1),&#x56E0;&#x4E3A;&#x53C2;&#x6570;1&lt;4,&#x6240;&#x4EE5;&#x6267;&#x884C;func(2),&#x4F46;&#x662F;&#x6B64;&#x65F6;&#x7684;func(1)&#x5E76;&#x6CA1;&#x6709;&#x6267;&#x884C;&#x5B8C;&#x6BD5;&#xFF0C;&#x53EA;&#x662F;&#x5728;&#x7B49;&#x5F85;func(2)&#x6267;&#x884C;&#x5B8C;&#x6BD5;&#x4E4B;&#x540E;&#x518D;&#x63A5;&#x7740;&#x6267;&#x884C;func(1)&#x5269;&#x4F59;&#x7684;&#x90E8;&#x5206;&#x3002;&#x5728;&#x6267;&#x884C;func(2)&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#x53C8;&#x4F1A;&#x6267;&#x884C;func(3)&#xFF0C;&#x63A5;&#x7740;&#x5728;&#x6267;&#x884C;func(4)&#xFF0C;&#x76F4;&#x5230;func(4)&#x4E4B;&#x540E;&#x4E0D;&#x6EE1;&#x8DB3;&#x6761;&#x4EF6;&#x5C31;&#x6253;&#x5370;&#x4E2D;&#x95F4;&#x7684; <code>========</code> &#x53F7;&#xFF0C;&#x518D;&#x4E00;&#x6B21;&#x6267;&#x884C;func(4)&#x3001;func(3)&#x3001;func(2)&#x3001;func(1)&#x5269;&#x4F59;&#x7684;&#x90E8;&#x5206;&#x5C31;&#x662F;&#x5C55;&#x793A;&#x7684;&#x7ED3;&#x679C;&#x3002;</p>
<pre><code class="lang-py"># &#x6267;&#x884C;&#x8FC7;&#x7A0B;&#x5206;&#x89E3;
func(1)  --&gt; 1 func(2) 1
             1 2 func(3) 2 1
             1 2 3 func(4) 3 2 1
             1 2 3 4 ===== 4 3 2 1
</code></pre>
<ul>
<li><h2 id="&#x7528;&#x9012;&#x5F52;&#x5199;&#x6C49;&#x8BFA;&#x5854;">&#x7528;&#x9012;&#x5F52;&#x5199;&#x6C49;&#x8BFA;&#x5854;</h2>
<pre><code class="lang-py">  def hannoi(n, a, b, c):
      if n == 1:
          print(a, &quot;---&gt;&quot;, c)
      else:
          hannoi(n-1, a, c, b)
          print(a, &quot;---&gt;&quot;, c)
          hannoi(n-1, b, a, c)
  if __name__ == &quot;__main__&quot;:
      hannoi(5, &quot;a&quot;, &quot;b&quot;, &quot;c&quot;)

  a ---&gt; c
  a ---&gt; b
  c ---&gt; b
  a ---&gt; c
  b ---&gt; a
  b ---&gt; c
  a ---&gt; c
  a ---&gt; b
  c ---&gt; b
  c ---&gt; a
  b ---&gt; a
  c ---&gt; b
  a ---&gt; c
  a ---&gt; b
  c ---&gt; b
  a ---&gt; c
  b ---&gt; a
  b ---&gt; c
  a ---&gt; c
  b ---&gt; a
  c ---&gt; b
  c ---&gt; a
  b ---&gt; a
  b ---&gt; c
  a ---&gt; c
  a ---&gt; b
  c ---&gt; b
  a ---&gt; c
  b ---&gt; a
  b ---&gt; c
  a ---&gt; c
</code></pre>
</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../../home/4.流程控制/2.循环结构.html" class="navigation navigation-prev " aria-label="Previous page: 循环结构"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../../home/5.函数及作用域/2.函数文档.html" class="navigation navigation-next " aria-label="Next page: 函数文档"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../../gitbook/app.js"></script>

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
